<?php
/**
 * @author HelloWorld
 * 2015-7-20
 * UTF-8
 */
class ShopLib_UserLoginKey{
    
    public static function getKey($uid,$time=0){
    
        $adminStr = ShopLib_GenerateEncrypt::decrypt($uid,ShopLib_TokenAuthConfig::$client_secret['user']);
        $admin = explode('|', $adminStr);
    
        if(!empty($admin) && isset($admin[1]))
            return $admin;
        else
            return null;
    }
    
    public static function createKey($key,$time = 0){
        $now = $time ? $time : time();
        $txt = $key.'|'.dechex($now);
        $uid = ShopLib_GenerateEncrypt::encrypt($txt,ShopLib_TokenAuthConfig::$client_secret['user']);
        // setcookie(self::$uidKey, $uid,null,'/',self::$domain);
        return $uid;
    }

    public static function lcDecrypt($token='',$keyType='user'){
        $clientSecret = array(
            'login' => 'xeVdfPaw',
            'user'  => 'tYaPpLiCaI'
        );
        $token  = ShopLib_UserLoginKey::getKey($token,$clientSecret[$keyType]);
        $token  =  explode('&',$token[0]);
        $userInfo = array();
        if( count($token)  == 4  &&  $token[0] > 0 ){
            $userInfo['uid'] = $token[0];
            $userInfo['username'] = urldecode($token[1]);
        }
        return $userInfo;
    }

}
